package com.ctshk.sapp.bus.controller;

import java.util.List;

import javax.validation.Valid;

import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ctshk.common.dto.Result;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.req.MainTreeData;
import com.ctshk.common.req.OperationByIdReq;
import com.ctshk.common.req.OperationByLikeReq;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.bus.dto.BusStopsDTO;
import com.ctshk.rpc.bus.req.BusStopsDictListQueryReq;
import com.ctshk.rpc.bus.req.BusStopsPassDictListQueryReq;
import com.ctshk.rpc.bus.req.BusStopsQueryReq;
import com.ctshk.rpc.bus.req.BusStopsSaveReq;
import com.ctshk.rpc.bus.service.IBusStopsService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * <p>
 * 巴士站点表 前端控制器
 * </p>
 *
 * @author 彭柳霖
 * @since 2021-02-08
 */
@Api(value="资源中心-巴士站点信息", tags="资源中心-巴士站点信息")
@RestController
@RequestMapping("/bus-stops")
public class BusStopsController extends BaseController {

    @DubboReference
    private IBusStopsService busStopsService;

    /**
     * 查询所有巴士站点列表
     * @return
     */
    @PostMapping("/list")
    public Result<List<BusStopsDTO>> queryBusLineList() {
        List<BusStopsDTO> busStopsDTOList = busStopsService.queyList();
        return Result.success(busStopsDTOList);
    }


    /**
     * 中港通API站点
     * @return
     */
    @PostMapping("/importHkt")
    public Result importHkt() throws Exception{
        busStopsService.importHktBusStop();
        return Result.success();
    }


    /**
     * 中汽API站点
     * @return
     */
    @PostMapping("/importRgl")
    public Result importRgl() throws Exception{
        busStopsService.importRglBusStop();
        return Result.success();
    }

    @ApiOperation("查询巴士站点列表")
    @PostMapping("queryStopsList")
    public Result<PageResponse<BusStopsDTO>> queryStopsList(@RequestBody BusStopsQueryReq req) {
		return busStopsService.queryStopsList(req);
	}
    
    @ApiOperation("保存巴士站点")
    @PostMapping("saveStops")
    public Result<Void> saveStops(@RequestBody @Valid BusStopsSaveReq req) {
		return busStopsService.saveStops(req, getCurrentUser());
	}
    
    @ApiOperation("删除巴士站点")
    @PostMapping("deleteStops")
    public Result<Void> deleteStops(@RequestBody @Valid OperationByIdReq req) {
		return busStopsService.deleteStops(req, getCurrentUser());
	}
    
    @ApiOperation("启用/禁用巴士站点")
    @PostMapping("changeStopsStatus")
    public Result<Void> changeStopsStatus(@RequestBody @Valid OperationByIdReq req) {
		return busStopsService.changeStopsStatus(req, getCurrentUser());
	}
    
    @ApiOperation("查询巴士站点数据字典列表")
    @PostMapping("queryStopsDictList")
    public Result<PageResponse<MainTreeData>> queryStopsDictList(@RequestBody BusStopsDictListQueryReq req) {
		return busStopsService.queryStopsDictList(req);
	}
    
    @ApiOperation("查询巴士经停站站点数据字典列表")
    @PostMapping("queryStopsPassDictList")
    public Result<PageResponse<MainTreeData>> queryStopsPassDictList(@RequestBody BusStopsPassDictListQueryReq req) {
		return busStopsService.queryStopsPassDictList(req);
	}
    
    @ApiOperation("检索巴士城市列表")
    @PostMapping("searchCityList")
    public Result<PageResponse<MainTreeData>> searchCityList(@RequestBody OperationByLikeReq req) {
		return busStopsService.searchCityList(req);
	}
}
